package com.ht.base.system.biz.convert;

import com.ht.base.system.common.pojo.bo.SysPostBO;
import com.ht.base.system.dao.domain.SysPostDO;
import org.base.common.appexception.AppErrorCodeEnum;
import org.base.common.appexception.AppException;
import org.base.common.constans.SystemConstant;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 类SysPostBeanUtil.java的实现描述：岗位信息表工具类
 * 
 * @Author hdengxian
 * @Date 2023年05月26日
 */
public class SysPostBeanUtil {

    private SysPostBeanUtil(){
    }

    public static SysPostDO sysPostBOToDO(SysPostBO srcObj) {
        if (srcObj == null) {
            return null;
        }
        SysPostDO targetObj = new SysPostDO();
        /**岗位ID**/
        targetObj.setId(srcObj.getSysPostId());
        /**岗位编码**/
        targetObj.setPostCode(srcObj.getPostCode());
        /**岗位名称**/
        targetObj.setPostName(srcObj.getPostName());
        /**显示顺序**/
        targetObj.setPostSort(srcObj.getPostSort());
        /**状态（0正常 1停用）**/
        targetObj.setStatus(srcObj.getStatus());
        /**创建者**/
        targetObj.setCreateBy(srcObj.getCreateBy());
        /**创建时间**/
        targetObj.setCreateTime(srcObj.getCreateTime());
        /**更新者**/
        targetObj.setUpdateBy(srcObj.getUpdateBy());
        /**更新时间**/
        targetObj.setUpdateTime(srcObj.getUpdateTime());
        /**备注**/
        targetObj.setRemark(srcObj.getRemark());
        return targetObj;
    }

    public static SysPostBO sysPostDOToBO(SysPostDO srcObj) {
        if (srcObj == null) {
            return null;
        }
        SysPostBO targetObj = new SysPostBO();
        /**岗位ID**/
        targetObj.setSysPostId(srcObj.getId());
        /**岗位编码**/
        targetObj.setPostCode(srcObj.getPostCode());
        /**岗位名称**/
        targetObj.setPostName(srcObj.getPostName());
        /**显示顺序**/
        targetObj.setPostSort(srcObj.getPostSort());
        /**状态（0正常 1停用）**/
        targetObj.setStatus(srcObj.getStatus());
        /**创建者**/
        targetObj.setCreateBy(srcObj.getCreateBy());
        /**创建时间**/
        targetObj.setCreateTime(srcObj.getCreateTime());
        /**更新者**/
        targetObj.setUpdateBy(srcObj.getUpdateBy());
        /**更新时间**/
        targetObj.setUpdateTime(srcObj.getUpdateTime());
        /**备注**/
        targetObj.setRemark(srcObj.getRemark());
        return targetObj;
    }

    public static List<SysPostBO> doList2BOList(List<SysPostDO> doList) {
        List<SysPostBO> boList = new ArrayList<>();
        if (CollectionUtils.isEmpty(doList)) return boList;

        doList.stream().forEach(d -> boList.add(SysPostBeanUtil.sysPostDOToBO(d)));
        return boList;
    }

    public static List<SysPostDO> boList2DOList(List<SysPostBO> boList) {
        List<SysPostDO> doList = new ArrayList<>();
        if (CollectionUtils.isEmpty(boList)) return doList;

        boList.stream().forEach(b -> doList.add(SysPostBeanUtil.sysPostBOToDO(b)));
        return doList;
    }

    public static void savePostCheckParam(SysPostBO post) {
        if (post == null) {
            throw new AppException(AppErrorCodeEnum.PARAMETER_ERROR);
        }
        if (StringUtils.isBlank(post.getPostName())) {
            throw new AppException(AppErrorCodeEnum.PARAMETER_ERROR);
        }
        if (StringUtils.isBlank(post.getPostCode())) {
            throw new AppException(AppErrorCodeEnum.PARAMETER_ERROR);
        }
        if (StringUtils.isBlank(post.getStatus())) {
            post.setStatus(SystemConstant.STR_0);
        }
    }
}